package com.reform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reform.pojo.phase.ViewBatchPhase;
import com.reform.mapper.ViewBatchPhaseMapper;
import com.reform.res.Result;
import com.reform.res.ResultCode;
import com.reform.service.IViewBatchPhaseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author mortale
 * @since 2021-09-12
 */
@Service
public class ViewBatchPhaseServiceImpl extends ServiceImpl<ViewBatchPhaseMapper, ViewBatchPhase> implements IViewBatchPhaseService {

    @Autowired
    ViewBatchPhaseMapper viewBatchPhaseMapper;

    @Override
    public Result getAllBatchPhase() throws SQLException {
        return Result.success(ResultCode.SUCCESS, viewBatchPhaseMapper.selectList(null));
    }

    @Override
    public Result getBatchPhaseByPhaseId(String phaseId) throws SQLException {
        return Result.success(ResultCode.SUCCESS, viewBatchPhaseMapper.selectList(new QueryWrapper<ViewBatchPhase>().eq("phase_id", phaseId)));
    }

    @Override
    public Result getBatchPhaseByBatchId(String batchId) throws SQLException {
        return Result.success(ResultCode.SUCCESS, viewBatchPhaseMapper.selectList(new QueryWrapper<ViewBatchPhase>().eq("batch_id", batchId)));
    }

    @Override
    public Result getSelectByPhaseId(String phaseId) {
        return Result.success(ResultCode.SUCCESS, viewBatchPhaseMapper.selectList(new QueryWrapper<ViewBatchPhase>().eq("phase_id", phaseId)));
    }

    @Override
    public Result getNotSelectPhaseByPhaseId(String phaseId) {
        return null;
    }

    @Override
    public Result getBatchNameByPhaseId(String phaseId) {
        Map<String, Object> map = new HashMap<>();
        map.put("batchNames", viewBatchPhaseMapper.getBatchNameByPhaseId(phaseId));
        return Result.success(ResultCode.SUCCESS, map);
    }
}
